package task06_06;

import task01.GuessNumber;

import java.util.Scanner;

public class UserTest {
    private static UserDao userDao=new UserDaoList() ;

    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while(true){
            choose();
            int num=scanner.nextInt();
            switch (num){
                case 1:
                    loginFace();
                    break;
                case 2:
                    registerFace();
                    break;
                case 3:
                    System.out.println("欢迎下次光临");
                    System.exit(0);
                    break;
                case 4:
                    showFace();
                    break;
                default:
                    System.out.println("输入有误");
            }
        }
        

    }

    private static void showFace() {
        System.out.println("所有注册的用户信息：");
        userDao.show();

    }

    private static void registerFace() {
        System.out.println("--------注册界面--------");
        System.out.println("请输入用户名：");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        System.out.println("请输入密码：");
        String password=scanner.nextLine();

        User user=new User(name,password);
        userDao.register(user);
        System.out.println("注册成功");
    }

    private static void loginFace() {
        System.out.println("--------注册界面--------");
        System.out.println("请输入用户名：");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        System.out.println("请输入密码：");
        String password=scanner.nextLine();
        boolean flag= userDao.login(name,password);
        if(flag){
            System.out.println("登陆成功,可以玩游戏啦！");
            GuessNumber.start();
        }else{
            System.out.println("登陆失败，用户名或密码错误");
        }

    }

    private static void choose(){
        System.out.println("--------欢迎光临--------");
        System.out.println("1 登陆");
        System.out.println("2 注册");
        System.out.println("3 退出");
        System.out.println("4 遍历");
        System.out.println("请输入你的选择：");
    }
}
